﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ATSModel;
using ATSDAL;
using System.Collections.Generic;
using CrystalDecisions.CrystalReports.Engine;

public partial class PIMTest_PIMTestDetails_ViewPIMTestItem : System.Web.UI.Page
{
    string pIMproductSN = "";
    DateTime pIMRecordTimes=DateTime.Now;
    string productTypeIDs = "";
    string userIDs = "";
    string pIMENAIDs = "";
    string pIMPasses = "";
    string userID2 = "";
    private ReportDocument doc = new ReportDocument();
    protected void Page_Load(object sender, EventArgs e)
    {
        this.Page.Unload += new EventHandler(Page_Unload);
   
            //pIMproductSN = Request.QueryString["ProductSN"];
            //pIMRecordTimes = Request.QueryString["PIMRecordTime"];
            //productTypeIDs = Request.QueryString["ProductTypeID"];
            //userIDs = Request.QueryString["UserID"];
            //pIMENAIDs = Request.QueryString["PIM_ENAID"];
            //pIMPasses = Request.QueryString["PIMPass"];
            //Bind(); 
    }

    public IList<PIMTestItemInfo> GetData()
    {
        IList<PIMTestItemInfo> testItems = new List<PIMTestItemInfo>();
        PIMTestItem testItem = new PIMTestItem();
        string str = pIMproductSN;
        DateTime dt = (DateTime)Session["pIMRecordTime"];  
        testItems = testItem.GetTestItems(str, dt);
        return testItems;
    }

    protected void CrystalReportViewer1_Init(object sender, EventArgs e)
    {
        string Mark = Request.QueryString["Mark"];
        if (Mark == "ViewByProuctSN")
        {
            pIMproductSN = (string)Session["ProductSN"];
            pIMRecordTimes = (DateTime)Session["pIMRecordTime"];
            productTypeIDs = (string)Session["ProductTypeID"];
            userIDs = (string)Session["UserID"];
            userID2 = (string)Session["UserID2"];
            pIMENAIDs = (string)Session["PIM_ENAID"];
            pIMPasses = (string)Session["PIMPass"];
        }
        else
        {
            pIMproductSN = Request.QueryString["ProductSN"];
            pIMRecordTimes = (DateTime)Session["pIMRecordTime"];
            productTypeIDs = Request.QueryString["ProductTypeID"];
            userIDs = Request.QueryString["UserID"];
            userID2 = Request.QueryString["UserID2"];
            pIMENAIDs = Request.QueryString["PIM_ENAID"];
            pIMPasses = Request.QueryString["PIMPass"];
        }
  
        ForCrystalReport();
    }

    
    protected void ForCrystalReport()
    {
        doc.Load(Server.MapPath("ViewPIMTestItemReport.rpt")); 

        TextObject txtProductSN = (TextObject)doc.ReportDefinition.ReportObjects["Text2"];
        txtProductSN.Text = "产品序列号：" + pIMproductSN;
        TextObject txtTestTime = (TextObject)doc.ReportDefinition.ReportObjects["Text4"];
        txtTestTime.Text = "测试时间：" + pIMRecordTimes;
        TextObject txtProductTypeID = (TextObject)doc.ReportDefinition.ReportObjects["Text8"];
        txtProductTypeID.Text = "产品代码：" + productTypeIDs;
        TextObject txtUserID = (TextObject)doc.ReportDefinition.ReportObjects["Text9"];
        txtUserID.Text = "测试员工：" + userIDs + "," + userID2;
        TextObject txtENAID = (TextObject)doc.ReportDefinition.ReportObjects["Text10"];
        txtENAID.Text = "失网编号：" + pIMENAIDs;
        TextObject txtIsPass = (TextObject)doc.ReportDefinition.ReportObjects["Text11"];
        txtIsPass.Text = "是否通过：" + pIMPasses;
         

        IList<PIMTestItemInfo> list = GetData();
        doc.SetDataSource(list);
        this.CrystalReportViewer1.ReportSource = doc;
    }

    private void Page_Unload(object sender, EventArgs e)
    {
        doc.Dispose();
    }

    protected void Bind()
    {
        //PIMGridViewItem.DataSource = GetData();
        //PIMGridViewItem.DataBind();
        //for (int i = 0; i < PIMGridViewItem.Rows.Count; i++)
        //{
        //    if (PIMGridViewItem.Rows[i].Cells[5].Text == "Fail")
        //        PIMGridViewItem.Rows[i].Cells[5].ForeColor = System.Drawing.Color.Red;
        //}
        //productSNId.Text = pIMproductSN;
        //pIMRecordTimeId.Text = pIMRecordTimes;
        //productTypeId.Text = productTypeIDs;
        //userId.Text = userIDs;
        //pIMENAId.Text = pIMENAIDs;
        //pIMPassId.Text = pIMPasses;
    } 
}


  

 

  

    

